//
//  ListView.m
//  UI6_UIScrollView_UIPageControl相册作业
//
//  Created by dllo on 15/11/14.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "ListView.h"
#import "PhotoView.h"

@implementation ListView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}


- (void)createSubviews
{
    self.backgroundColor = [UIColor whiteColor];
    
    UIScrollView *scrollV = [[UIScrollView alloc] initWithFrame:self.frame];
    scrollV.contentSize = CGSizeMake(0, self.frame.size.height * 3);
    scrollV.bounces = YES;
    scrollV.showsVerticalScrollIndicator = YES;
    [self addSubview:scrollV];
    [scrollV release];
    
    
    for (NSInteger i = 0; i < 19; i++) {
        NSString *fileName = [NSString stringWithFormat:@"image%ld.jpg", i + 1];
        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 102.5 * i + 50, self.frame.size.width, 102.5)];
        imageV.image = [UIImage imageNamed:fileName];
        imageV.userInteractionEnabled = YES;
        [scrollV addSubview:imageV];
        [imageV release];
        
        UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
        [imageV addGestureRecognizer:tapGR];
        [tapGR release];
        
    }
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(170, 25, 30, 30);
    button.backgroundColor = [UIColor yellowColor];
    [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    [scrollV addSubview:button];
    
    
}

- (void)buttonAction
{
    [self.delegate dismiss];
}

- (void)tapAction
{
//    NSLog(@"轻拍");
    [self.delegate show];
}


@end
